#include <rclcpp/rclcpp.hpp>
#include "base_interface_demo01/srv/add_int.hpp"
using base_interface_demo01::srv::AddInt;
class ServerService: public rclcpp::Node
{
public:
    ServerService():Node("addint_srv_node_cpp")
    {
        RCLCPP_INFO(this->get_logger(),"创建服务端节点");
        this->server_ = this->create_service<AddInt>(
            "add_int",
            std::bind(&ServerService::on_add, this, std::placeholders::_1, std::placeholders::_2));
    }
private:
    rclcpp::Service<AddInt>::SharedPtr server_;    
private:
    void on_add(const AddInt::Request::SharedPtr req,const AddInt::Response::SharedPtr resp)
    {
        resp->sum=req->num1+req->num2;
        RCLCPP_INFO(this->get_logger(),"%d+%d=%d",req->num1,req->num2,resp->sum);
    }    
};
int main(int argc, char ** argv)
{
    rclcpp::init(argc,argv);
    rclcpp::spin(std::make_shared<ServerService>());
    rclcpp::shutdown();
    return 0;
}